package com.base.core.model;

import com.base.core.constant.Enums;

import java.util.HashMap;

/**
 * 接口返回对象
 * @author 177****0334
 * @date 2020/12/23 09:49
 */
public class ApiRes extends HashMap<String, Object> {

    private Boolean success;

    private String message;

    private Object data;

    public ApiRes(Boolean success, String message, Object data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    /**
     * 请求成功
     * @author 177****0334
     * @date 2020/11/30 15:29
     */
    public static <T> ApiRes success(Object data) {
        return ApiRes.success("请求成功", data);
    }

    public static ApiRes success() {
        return ApiRes.success("请求成功", null);
    }

    /**
     * 请求成功
     * @author 177****0334
     * @date 2020/11/30 15:29
     */
    public static <T> ApiRes success(String message, Object data) {
        return new ApiRes(Boolean.TRUE, message, data);
    }

    /**
     * 请求失败
     * @author 177****0334
     * @date 2020/11/30 15:29
     */
    public static ApiRes failed() {
        return ApiRes.failed("请求失败");
    }

    /**
     * 请求失败
     * @author 177****0334
     * @date 2020/11/30 15:29
     */
    public static ApiRes failed(String message) {
        return new ApiRes(Boolean.FALSE, message, null);
    }

    public static ApiRes failed(Enums.ResponseStatus responseStatus) {
        return new ApiRes(Boolean.FALSE, responseStatus.getDesc(), null);
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}